#ifndef TOOLS_H
#define TOOLS_H

#include <QByteArray>
#include <QDebug>
#include <QtEndian>
#include <QFile>

#include <stdint.h>
#include <stdbool.h>

//#define RU(x,n)	(-(-(x) & -(n)))    //round up
#define RU(N, S) ((((N) + (S) - 1) / (S)) * (S))

#define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )
#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )

// debug helpers
#define DBG	qDebug() << __PRETTY_FUNCTION__ << "line" << __LINE__ << ::hex
#define WRN	qWarning() << __PRETTY_FUNCTION__ << "line" << __LINE__ << ::hex

typedef uint8_t			u8;
typedef uint16_t 		u16;
typedef uint32_t 		u32;
typedef uint64_t	 	u64;

typedef int8_t 			s8;
typedef int16_t 		s16;
typedef int32_t 		s32;
typedef int64_t		 	s64;

typedef volatile u8		vu8;
typedef volatile u16	vu16;
typedef volatile u32	vu32;
typedef volatile u64	vu64;

typedef volatile s8		vs8;
typedef volatile s16	vs16;
typedef volatile s32	vs32;
typedef volatile s64	vs64;

typedef float			f32;
typedef double			f64;

typedef volatile f32	vf32;
typedef volatile f64	vf64;

char ascii( char s );
void hexdump( const void *d, int len );
void hexdump( const QByteArray &d, int from = 0, int len = -1 );

//get a padded version of the given buffer
QByteArray PaddedByteArray( const QByteArray &orig, quint32 padTo );

//read a file into a bytearray
QByteArray ReadFile( const QString &path );

//save a file to disc
bool WriteFile( const QString &path, const QByteArray &ba );

#endif // TOOLS_H
